package cn.lds.j375.healthexam.service.impl;

import cn.lds.j375.healthexam.dto.ResultDTO;
import cn.lds.j375.healthexam.entity.ExamRecord;
import cn.lds.j375.healthexam.mapper.ExamRecordMapper;
import cn.lds.j375.healthexam.service.AppointmentRecordService;
import cn.lds.j375.healthexam.service.ExamRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExamRecordServiceImpl implements ExamRecordService {

    @Autowired
    private ExamRecordMapper examRecordMapper;
    @Autowired
    private AppointmentRecordService appointmentRecordService;

    private static final Logger log = LoggerFactory.getLogger(ExamRecordServiceImpl.class);

    @Override
    public ResultDTO<List<ExamRecord>> selectExamRecordAll() {

        List<ExamRecord> examRecords = examRecordMapper.selectExamRecordAll();

        log.info("log:{}",examRecords);

        return null;
    }

    @Override
    public ResultDTO<ExamRecord> selectExamRecordById(Integer id) {
        return null;
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public ResultDTO addExamRecord(ExamRecord examRecord) {

        //添加体检信息
        int insert = examRecordMapper.insert(examRecord);
        //修改预约状态
        if (insert > 0){
            appointmentRecordService.comfirmAppointmentRecord(examRecord.getAppointmentId());
        }


        return ResultDTO.buildSuccess();
    }
}
